<template>
	<view>
		
		<swiper class="goods-thumbnail" duration="1000" style="height:612rpx; width:750rpx; ">
			<swiper-item>
				<image :src="goods.thumbnail" mode="aspectFit" />
				<!-- <view>货品为真</view> -->
			</swiper-item> 
		</swiper>
		
		<view class="goods-box"> 
			<text class="goods-name clamp1">{{goods.name}}</text>
			<text class="description" style="margin: 32rpx 0;">生产厂家：{{goods.manufactor}}</text>
			<view style="margin: 20rpx 0;">
				<text class="description">产品参数：</text>
				<view style="display: flex; justify-content: space-between; margin-top: 10rpx;">
					<text class="description">品牌: {{goods.brand.name}}</text>
					<text class="description">型号: {{goods.attr.name}}</text>
				</view>
				<view style="display: flex; justify-content: space-between; margin-top:10rpx;">
					<text class="description">机油分类: {{goods.category.name}}</text> 
				</view>
			</view>
			<text class="description">{{goods.description}}</text>
		</view>
		<!-- 
		<view class="number-box u-border-top">
			<view class="buy-num">
				<text class="buy-num-title">购买数量：</text>
				<text class="buy-num-surplus">剩余227件</text>
			</view>
			<u-number-box v-model="value" @change="numChange"></u-number-box>
		</view> -->
		
<!-- 		<view class="number-box u-border-top" @click="couponShow = true">
			<text style="color: #ff8d00;">{{coupon_name ? coupon_name : '使用优惠券'}}</text>
			<u-icon color="#ff8d00" name="arrow-right"></u-icon>
		</view> -->
		
		<view class="content-box u-border-top" style="margin-bottom: 98rpx;">
			<view class="header"><text>商品详情</text></view>
			<view class="content">
				<u-parse :html="content" />
			</view>
		</view>
		
		<view class="navigation" v-if="mall_type == 1">
			<!-- <view class="price">合计:<text>￥{{goods.price}}</text></view> -->
			<view></view>
			<view class="buy btn u-line-1" @click="order">识别认证</view>
		</view>
		
		<u-select v-model="couponShow" :list="couponList" label-name="name" value-name="id" @confirm="couponConfirm"></u-select>
		 
	</view>
</template>
<script>
	
	export default {
		
		data() {
			return {
				goods:{},
				qrcodeId:0,
				content:"",
				photos:[],
				price:"0.00",
				couponShow:false,
				couponList:[],
				coupon_name:"",
				coupon_id:0,
				mall_type:2,
				is_state:0,
				entity_id:'',
			}
		},
		onLoad(options){
			 const url=options.q;
			
		// this.$u.toast(options.q);
		  // const url="https://rl.ccfqkj.com/api.php//mall/goods/get?sn=314&type=user";		
									console.log("132456",url);
			if(url){
				var _this=this;
				_this.$u.http.get(decodeURIComponent(url)).then(res => {
					if(res.code==1){
							uni.request({
										method:"get" ,//请求方式默认是get
										url:decodeURIComponent(url),
										success: (res) => {
											
											if(res.data.code){
													// uni.navigateTo({
													// 	url:"/pages/mall/info?id="+res.data.data
													// })
													_this.mall_type = uni.getStorageSync('mall_type');
													_this.$u.http.get("mall/goods/"+res.data.data).then(res => {
														_this.goods = res.data.goods;
														_this.price = res.data.goods.price;
														_this.content = res.data.goods.content;
														_this.photos = res.data.goods.more.photos;
														_this.qrcodeId = res.data.qrcode.id
														_this.is_state = res.data.is_state
														_this.entity_id = res.data.entity_id
													});
												}else{
													console.log("数据1111",res.data);
													_this.$u.toast(res.data.msg);
													setTimeout(function() {
															uni.switchTab({
																url:"/pages/index/index"
															})
													   }, 2500);
												}
										}
									})
					}else{
						_this.mall_type = uni.getStorageSync('mall_type');
						_this.$u.http.get("mall/goods/reada/").then(res => {
							_this.goods = res.data.goods;
							_this.price = res.data.goods.price;
							_this.content = res.data.goods.content;
							_this.photos = res.data.goods.more.photos;
							_this.qrcodeId = res.data.qrcode.id
							_this.is_state = res.data.is_state
							_this.entity_id = res.data.entity_id
						});
						console.log("3");
						// _this.$u.toast(res.msg,3000);
						uni.showToast({
							title:res.msg,
							icon: 'none',
							duration:3000,
							success:function(res){
								console.log("2",res);
								setTimeout(function() {
									  uni.$emit('refurbish',{})
										uni.switchTab({
											url:"/pages/index/index"
										})
								   }, 2500);
										
							}	
						})
					
					
						
					}
				})
				
					
			}else{
					console.log(options.id);
					this.mall_type = uni.getStorageSync('mall_type');
					this.$u.http.get("mall/goods/"+options.id).then(res => {
						this.goods = res.data.goods;
						this.price = res.data.goods.price;
						this.content = res.data.goods.content;
						this.photos = res.data.goods.more.photos;
						this.qrcodeId = res.data.qrcode.id
						this.is_state = res.data.is_state
						this.entity_id = res.data.entity_id
					});
			}
			
			
			// uni.$u.http.get("mall/coupon/my",{
			// 	status:1
			// }).then(res => {
			// 	console.log(res.data);
			// 	res.data.forEach((item,key) => {
			// 		this.couponList.push({
			// 			id:item.id,
			// 			name:item.coupon.name
			// 		});
			// 	})
			// })
		},
		methods: {
			useCoupon(){
				
			},
			couponConfirm(e){
				console.log(e);
				this.coupon_name = e[0].label;
				this.coupon_id = e[0].value;
			},
			order(){
				
				// let couponid = this.coupon_id ? this.coupon_id : 0;
				
				
				// this.$u.http.get("order/cart/createorder",{
				// 	id:this.goods.id,
				// 	couponid:couponid
				// }).then(res => {
				// 	if(res.code){
				// 		// uni.navigateTo({
				// 		// 	url:"/pages/order/confirm?order_sn=" + res.data.order_sn
				// 		// })
				// 		uni.navigateTo({
				// 			url:"/pages/order/scanface?order_sn=" + res.data.order_sn
				// 		})
				// 	}else{
				// 		this.$u.toast(res.msg);
				// 	}
				// });
				if(this.is_state==1){
					uni.navigateTo({
						url:"/pages/order/confirm?id=" + this.qrcodeId + "&entity_id=" + this.entity_id
					})
				}else{
					uni.navigateTo({
						url:"/pages/order/scanface?id=" + this.qrcodeId
					})
				}	
				
				
			},
			numChange(e){
				console.log(e);
			},
			toSwitch(url){
				uni.switchTab({
					url:url
				})
			},
			showModel(e){
				this.$refs.model.show();
			},
		}
	}
</script>

<style lang="less">
	.goods-thumbnail{
		background-color: #FFFFFF;
	}
	.goods-thumbnail image{
		width: 750rpx;
		height: 612rpx;
		display: block;
	}
	.goods-thumbnail view{
		position: absolute;
		bottom:5rem;
		right:0.2rem; 
		color: red;
		border: 2px solid red;
		border-radius: 2rem;
		width: 2.2rem;
		height: 2.2rem;
		font-size: 12px;
		text-align: center;
		padding-top: 2px;
	}
	.goods-box{
		background-color: #FFFFFF;
		padding: 32rpx;
		position: relative;
		
		.goods-name{
			font-size: 32rpx;
			font-weight: bold;
			margin-top: 24rpx;
		}
		.description{
			color: #666666;
			// margin-top: 18rpx;
			font-size: 24rpx;
			display: block;
			line-height: 1.5;
		}
		.goods-price{
			display: flex;
			flex-direction: row;
			align-items: flex-end;
			.price{
				color: #3c3c3c;
				font-weight: bold;
				font-size: 38rpx;
			}
			.original_price{ text-decoration:line-through; color:#999999; margin:0 16rpx; }
			.specialOffer{
				background-color: #ed3f14;
				color: #FFFFFF;
				padding: 6rpx;
				border-radius: 4rpx;
				font-size: 24rpx;
			}
		}
		.other{
			font-size: 24rpx;
			color: #999999;
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			margin-top: 32rpx;
		}
		
	}
	
	.content-box{ overflow: hidden;background: #FFFFFF; }
	.content-box .header{overflow:hidden;background: #FFFFFF;}
	.content-box .header text{ float:left; margin-left: 32rpx; font-size:30rpx; font-weight:bold; line-height: 84rpx; }
	.content-box .content{
		margin-bottom: 32rpx;
	}
	
	.number-box{
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
		background-color: #FFFFFF;
		padding: 32rpx;
		.buy-num{
			display: flex;
			flex-direction: column;
			flex: 1;
			.buy-num-title{
				font-size: 28rpx;
				font-weight: bold;
				display: flex;
				flex-direction: column;
			}
			.buy-num-surplus{
				font-size: 24rpx;
				color: #666666;
				margin-top: 12rpx;
				display: flex;
			}
		}
	}
	.navigation{
		position: fixed;
		bottom: 0;
		left: 0; right: 0;
		height: 124rpx;
		display: flex;
		flex-direction: row;
		z-index: 1;
		background-color: #FFFFFF;
		display: flex;
		flex-direction: row; 
		justify-content: space-between;
		padding: 16rpx 32rpx 0;
		.price{
			font-size: 24rpx; color:#ed3c11; font-weight: bold;
			text{
				font-size: 32rpx;
			}
		}
		.btn {
			line-height: 70rpx;
			height: 70rpx;
			border-radius: 35rpx;
			width: 240rpx;
			text-align: center;
			color: #ffffff;
			background-color: #2e8bf0;
		}
	}
	 
</style>
